<template >
	<view class="content">
		<message ref="Message"></message>
		<Header title="设置"></Header>
		<view class="list">
			<text class="list-title">播放</text>
			<view class="list-item">
				<text  class="left">自动登录</text>
				<switch :checked="autoSeting.autoLogin" @change="switchChange($event, 'autoLogin')" color="#32CCBC"/>
			</view>
			<view class="list-item">
				<text  class="left">自动续播</text>
				<switch :checked="autoSeting.autoShoot" @change="switchChange($event,'autoShoot')" color="#32CCBC"/>
			</view>
			<view class="list-item">
				<text  class="left">自动换源</text>
				<switch  :checked="autoSeting.autoChange" @change="switchChange($event,'autoChange')" color="#32CCBC"/>
			</view>
		</view>
		
		<view class="list">
			
			<view class="list-item ui-list right">
				<text class="left">当前版本</text>
				<view class="right">
					<text>{{ version }}</text>
					<image src="/static/images/right.png" mode=""></image>
				</view>
			</view>
			<view class="list-item ui-list right" @click="aboutClick">
				<text  class="left">关于矩龙影视</text>
				<view class="right">
					<image src="/static/images/right.png" mode=""></image>
				</view>
				
			</view>
		</view>
		
		<view class="outlogin" @click="outLoginClick" v-if="loginStatus">
			退出登录
		</view>
	</view>
</template>

<script>
	import Header from '@/components/header/header.vue'
	export default {
		components: {
			Header
		},
		data() {
			return {
				loginStatus: false,
				autoSeting: {
					autoLogin: true,
					autoShoot: false,
					autoChange: false
				},
				version: 0
			};
		},
		onLoad() {
			const autoInfo = uni.getStorageSync('autoSeting')
			if (autoInfo) {
				this.autoSeting = autoInfo
			}
			this.loginStatus = getApp().globalData.loginStatus
			this.version = plus.runtime.version
		},
		methods: {
			async outLoginClick() {
				this.$refs['Message'].success('已退出登录')
				getApp().globalData.userInfo = ''
				getApp().globalData.loginStatus = false
				// uni.removeStorage({
				// 	key: 'userInfo',
				// 	success() {
				// 		console.log('退出登录成功')
						
				// 	}
				// })
				await this.$promise(500)
				uni.navigateBack()
			},
			switchChange(event, name) {
				this.autoSeting[name] = event.detail.value
				uni.setStorage({
					key: 'autoSeting',
					data: this.autoSeting,
					success() {
						console.log('更新成功')
					}
				})
			},
			aboutClick() {
				this.$goto('/pages/about/about')
			}
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		height: 100%;
		background-color: #f7f8fa;
	}
	.list {
		margin-top: 50rpx;
		
		.list-title {
			display: block;
			margin: 0 0 10rpx 20rpx;
			color: #706b6f;
		}
	}
	.list-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		height: 100rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #f7f8fa;
		box-sizing: border-box;
		
		.left {
			margin-left: 20rpx;
			font-size: 16px;
			
		}
		.right {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-right: 20rpx;
			image {
				width: 64rpx;
				height: 64rpx;
			}
		}
		
		switch {
			margin-right: 20rpx;
		}
		
		
	}
	.list-item:active {
		background-color: rgba(0,0,0,0.02);
	}
	.outlogin {
		width: 100%;
		height: 100rpx;
		margin-top: 100rpx;
		text-align: center;
		line-height: 100rpx;
		background-color: #fff;
		color: #EA5455;
		
	}
</style>
